
<%
    Users user = Trader.getUser(request.getParameter("uid"));
	wstrader.task.traffic.si.Instruction task = user.traffic.si.sIns;

	if (!user.Authenticated()) {
		response.sendRedirect("logon.jsp");
		return;
	}
	((Tasks)task.getOwner()).clearFocus();
	task.setFocus(true);	
	Trader.window_width = "90%";

%>

<%@include file="../header.jsp"%>

<%
	ResultSet rs=null;

	long focused_id = task.doTask();	
	System.out.println("Focused Id:- " + focused_id);
	Record ref = new Record(task.getShippingInstDetails());
	int cid=ref.getIntValue("contract_id");
	System.out.println("SipIns CI- "+cid);
	Record rc  = new Record(task.getContractDetails(cid));
	long new_id = task.getLastID("shipping_instruction") + 1;
	int mode = Utils.strToInt(request.getParameter("shipping_instruction"));
	System.out.println("Checking......."+request.getParameter("shipping_instruction"));
	String RefNo="";
	
	String Dt=	Utils.dateToStr(Utils.today());
	String Tm =Utils.timeToStr(Utils.now());
%>
<script language="javascript">
function doAllocation()
{
	doLink("warehouse.allocation.jsp?alloc_type=S");
}

function listView()
{
	var form = document.formMain;
	form.action = "traffic.si.jsp";
	form.submit();
}

function doAddNew()
{
	var form = document.formMain;
	var value = "New SI";
	var value1 = "<%=task.getNew_SI()%>";
	if (addNewListItemById("shipping_instruction",value) < 0) return;
	form.new_rec.value="0";
	setValue("ref_number",value1);
	form.date.value = "<%=Dt%>"
	form.time.value = "<%=Tm%>"
	setText("si_date_","<%=Dt%>")
	setText("si_time_","<%=Tm%>")
	
}


function doAddNewSi()
{
	var form = document.formMain;
	var value = "New SI";
	var value1 = "<%=task.getNew_SIRef()%>";
	if (addNewListItemById("shipping_instruction",value) < 0) return;
	form.new_rec.value="0";
	setValue("ref_number",value1);	

}

function doUpdate()
{
	var form = document.formMain;
	doTask(1);
}

function showClicked()
{
	if (isVisibled("wn_show_")) {
		hide("wn_show_");
		setText("wn_plus_","+");
		setValue("wn_show", 0);
	} else {
		show("wn_show_");
		setText("wn_plus_","-");
		setValue("wn_show", 1);
	}
}

function new_Container(i)
{
	alert(i);
	show("wn_" + i);
	setValue("wn_date_" + i, getNewDate());
	setValue("wn_time_" + i, getNewTime());
	highlightOn(getObj("wn_" + i),1);
}	

function ajaxTable( page )
{

	var xmlHttp;
	var form = document.formMain;
	//alert(parseFloat(form.ChkAlcTon.value));
	//alert(parseFloat(form.cnttons.value));
	
	if (parseFloat(form.ChkAlcTon.value) < parseFloat(form.cnttons.value))
	{

		form.uid_gid.value = form.uid.value + "-" + form.grade_id.value;
		page = page + "?uid="+form.uid_gid.value;

		try
  		{  
  			xmlHttp=new XMLHttpRequest();  
  		}
		catch (e)
  		{  // Internet Explorer  
  			try
    		{    
				xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");    
			}
  			catch (e)
    		{    
				try
      			{      
	  				xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");      
	  			}
    			catch (e)
      			{      
	  				alert("Your browser does not support AJAX!");      
					return false;      
	  			}    
	 		}  
		}
  		xmlHttp.onreadystatechange=function()
    	{
		
    		if(xmlHttp.readyState==4)
      		{
      			document.getElementById("AjTbl").innerHTML=xmlHttp.responseText;
      		}
    	}
  			xmlHttp.open("GET",page,true);
  			xmlHttp.send(null);  
  	}
	else
	{
		alert("Shipping Instruction is fully allocated.");
	}
}
  
function doOnClic_Alc()
{
 	var form = document.formMain;
	var type ="";
	form.sel_id.value ="";
	var iEnd= form.dRow.value;
	var i=1;
	
	while (i <= iEnd)
	{
		var AlcTon = getObj("Alc_"+i);
		var AlcId = getObj("Alc_id_"+i);
		var Avlton = getObj("Avl_ton_"+i);
		if (AlcTon == null) break;
		if (AlcTon.value > 0) 
		{
			//alert(parseFloat(AlcTon.value));
			//alert(parseFloat(Avlton.value));
			if (parseFloat(AlcTon.value) <= parseFloat(Avlton.value))
			{
				var v = AlcTon.value + "/" + AlcId.value;
				if (form.sel_id.value=="")
				{
					form.sel_id.value=  v;
				}
				else
				{
					form.sel_id.value=  form.sel_id.value+"," + v;
				}
			}
			else
			{
				alert("Value entered is more than the available quantity");
			}
		}
		i=i+1;
	}
	alert(form.sel_id.value);
}
  
function setDefault(id,valid)
{
  	var form = document.formMain;
	var def = getValue(valid);
	setValue(id,def)
}
  
function doUpdAllocation()
{
    var form = document.formMain;
	doOnClic_Alc();
  	doTask(3);
}  

function doUpdateWNI()
{
    var form = document.formMain;
  	doTask(4);
}  
</script>



<link href="style.css" rel="stylesheet" type="text/css">
<form method="POST" name="formMain" action="" onSubmit="">				  

<table width="100%"  border="0" class="style2">
	<tr class="style1">
	  <td colspan="2"><img src="images/shipping-instruction.jpg" width="300" height="30">
      <input type="hidden" name="contracts"  id="contracts"  value="<%=rc.getInt("id")%>">
      <input name="new_rec" type="hidden" id="new_rec" value="0">
      <input name="uid_gid" type="hidden" id="uid_gid" value="0" /></td>
    </tr>
	<tr class="style1" bgcolor="#EEEEEE">
	  <td width="15%" align="center">SI Ref</td>
	  <td width="85%">Detail</td>
  </tr>
	<tr>
	  <td height="261" valign="top"><table width="100%"  border="0" class="style2">
        <tr valign="top">
          <td><select name="shipping_instruction" size=18 class="style2" id="shipping_instruction" style="width:100%;" onChange="doPost();">
            <%//task.getResponse().setOptionX(task.getSI_List());%>
			<%//task.getResponse().setSelected("inst_id",si_id);%>
                    <%@include file="include/ShippingInsRefNoList.jsp"%>			
          </select></td>
        </tr>
        <tr>
          <td><img src="images/delete.gif" width="15" height="15" border="0" onClick="del_SI()"></td>
          </tr>
        <tr >
          <td height="20"><table width="100%"  border="1" cellpadding="0" cellspacing="0" class="style2">
            <tr align="center" bgcolor="#EEEEEE">
              <td colspan="2"><strong>Contracts Allocated </strong></td>
              </tr>
            <tr align="center" bgcolor="#EEEEEE">
              <td width="69%">Number </td>
              <td width="31%">Mts</td>
            </tr>
<%
	ResultSet rsAlc = task.getContract_Allocated();
	int total_allocated_bags = 0;
	float total_allocated_tons = 0;
	String contract_list = "";
	//Record rc;
	//Record rca = new Record(task.getContract_Allocated());
	rsAlc.beforeFirst();
	while (rsAlc.next()) {
		//int   allocated_bags = rca.getIntValue("allocated_bags");
		float allocated_tons = rsAlc.getFloat("weight_out");
		//total_allocated_bags += allocated_bags;
		total_allocated_tons += allocated_tons;
		//contract_list += (" + " + rca.getString("contract_no"));
		//String ct_allocated = rca.getString("contract_no");// + " / " rc.getString("ref_number").substring(3);
%>			
            <tr onClick="highlightOn(this)">
              <td align="left"><%=task.getFieldValueForId("weight_note","ref_number",rsAlc.getInt("wn_id"))%></td>
              <td align="right"><%=rsAlc.getFloat("weight_out")%></td>
            </tr>
<%
	}
	//if (contract_list.length() > 0) contract_list = contract_list.substring(3);
%>			
	<tr bgcolor="EEEEEE">
		<td align="left"><strong>Total
		  <input type="hidden" name="ChkAlcTon" id="ChkAlcTon" class="style2" style="width:80px; text-align:" value="<%=Utils.numberToStr(total_allocated_tons,1)%>" />
		</strong></td>
		<td align="right"><strong><%=Utils.numberToStr(total_allocated_tons,1)%></strong></td>
	</tr>
          </table></td>
        </tr>
      </table></td>
	  <td valign="top"><table width="100%"   border="1" cellpadding="0" cellspacing="0">
  		<tr>
    		<td ><table width="100%"  border="0" cellpadding="1" cellspacing="1" class="style2">
              <tr>
                <td colspan="5"><table width="100%"  border="0" cellspacing="1" cellpadding="1">
                  <tr>
                    <td width="46%" valign="top"><table width="100%"  border="0" cellpadding="1" cellspacing="1" class="style2">
                      <tr>
                        <td align="right">Ref Number &nbsp;</td>
                        <td colspan="4" style="font-weight:bold"><%=ref.getString("cnt_ref_number")%><strong>
                          <input name="contract_id" type="hidden" id="contract_id" value=<%=ref.getIntValue("contract_id")%>>
                        </strong></td>
                      </tr>
                      <tr>
                        <td align="right">Contract No &nbsp;</td>
                        <td colspan="4" style="font-weight:bold"><%=ref.getString("contract_no")%></td>
                      </tr>
                      <tr>
                        <td width="33%" align="right"><label id="e23">SI Ref &nbsp;</label></td>
                        <% String refno = (mode > 0) ?  ref.getString("ref_number") : ""; %>
                        <td colspan="4" style="font-weight:bold"><input name="ref_number" type="text" class="textnoedit" id="ref_number" value="<%=refno%>">                        </td>
                      </tr>
                      <tr>
                        <td align="right"><label id="e25">Date &nbsp;</label></td>
                        <% String sidt = (mode > 0) ?  ref.getDate("date") : ""; %>
                        <td width="20%" style="font-weight:bold"><label id="si_date_"><%=sidt%>
                            <input name="date" type="hidden" id="date" value=<%=sidt%>>
                        </label></td>
                        <% String sitime = (mode > 0) ?  ref.getDate("time") : ""; %>
                        <td colspan="3" style="font-weight:bold"><label id="si_time_"><%=sitime%>
                            <input name="time" type="hidden" id="time" value=<%=sitime%>>
                        </label></td>
                      </tr>
                      <tr>
                        <td align="right">Supplier &nbsp;</td>
                        <td colspan="4"><select name="supplier_id" id="supplier_id" class="textnoedit" style="width:100%;" onChange="">
                          <option value="0"></option>
                          <%task.getResponse().setOption(task.getCompanyList("supplier,buyer"));%>
                          <%task.getResponse().setSelected("supplier_id", ref.getIntValue("supplier_buyer_id"));%>
                        </select></td>
                      </tr>
                      <tr>
                        <td align="right">Buyer &nbsp;</td>
                        <td colspan="4"><select name="buyer_id" id="buyer_id" class="textnoedit" style="width:100%;" onChange="">
                          <option value="0"></option>
                          <%task.getResponse().setOption(task.getCompanyList("supplier,buyer"));%>
                          <%task.getResponse().setSelected("buyer_id", ref.getIntValue("supplier_buyer_id"));%>
                        </select></td>
                      </tr>
                      <tr>
                        <td align="right">&nbsp;</td>
                        <td colspan="4"><input type="hidden" name="grade_code" id="grade_code" class="style2" style="width:80px; text-align:" value="<%=task.getFieldValueForId("grade_master","grade_code",ref.getIntValue("grade_id"))%>" onChange="codeChanged(this);"></td>
                      </tr>
                      <tr>
                        <td align="right">Origin &nbsp;</td>
                        <td colspan="4"><select name="origin_id" id="origin_id" class="textnoedit" style="width:50%;" onChange="originChanged(this);">
                          <option value="0"></option>
                          <%task.getResponse().setOption(task.getMasterList("origin_master"));%>
                          <%task.getResponse().setSelected("origin_id", ref.getIntValue("origin_id"));%>
                        </select></td>
                      </tr>
                      <tr>
                        <td align="right">Quality &nbsp;</td>
                        <td colspan="4"><select name="quality_id" id="quality_id" class="textnoedit" style="width:50%;" onChange="qualityChanged(this);">
                          <option value="0"></option>
                          <%task.getResponse().setOption(task.getMasterList("quality_master"));%>
                          <%task.getResponse().setSelected("quality_id", ref.getIntValue("quality_id"));%>
                        </select></td>
                      </tr>
                      <tr>
                        <td align="right">Grade &nbsp;</td>
                        <td colspan="4"><select name="grade_id" id="grade_id" class="textnoedit" style="width:100%;" onChange="gradeChanged(this);">
                          <option value="0"></option>
		                  <%task.getResponse().setOption(task.getMasterList("grade_master"));%>
                          <%task.getResponse().setSelected("grade_id", ref.getIntValue("grade_id"));%>
                        </select></td>
                      </tr>
                      <tr>
                        <td align="right">Contract Tons&nbsp;</td>
                        <td colspan="4"><strong><%=ref.getFloatValue("cnttons")%> &nbsp;Mts
                          <input name="cnttons" type="hidden" id="cnttons" value="<%=ref.getFloatValue("cnttons")%>" />
                        </strong></td>
                      </tr>
                      <tr>
                        <td align="right"><label id="e28">Shipment &nbsp;</label></td>
                        <td colspan="4"><select name="packing_id" id="packing_id" class="style2" style="width:95%;" onChange="">
                            <option value="0"></option>
			                <%task.getResponse().setOption(task.getMasterList("packing_master"));%>
            			    <%task.getResponse().setSelected("packing_id", ref.getIntValue("packing_id"));%>
                         </select></td>
                      </tr>
                      <tr>
                        <td align="right">Quantity &nbsp;</td>
                        <td colspan="4"><input type="text" name="tons" id="tons" class="style2" style="width:80px; text-align:right" value="<%=ref.getFloatValue("tons")%>" onChange="tonsChanged(this.value);">&nbsp;Mts</td>
                      </tr>
                      <tr style="display:none">
                        <td align="right">Kg per Bag &nbsp;</td>
                        <td colspan="4"><input type="text" name="kg_per_bag" id="kg_per_bag" class="style2" style="width:80px; text-align:right" value="<%=ref.getFloatValue("kg_per_bag")%>"></td>
                      </tr>
                      <tr style="display:none">
                        <td align="right">No of Bags &nbsp;</td>
                        <td colspan="4"><input type="text" name="no_of_bags" id="no_of_bags" class="style2" style="width:80px; text-align:right" value="<%=ref.getInt("no_of_bags")%>"></td>
                      </tr>
                      <tr>
                        <td rowspan="2" align="right">Shipping &nbsp;<br>Period &nbsp;</td>
                        <td><em>From</em></td>
                        <td width="6%">&nbsp;</td>
                        <td width="21%"><em>To</em></td>
                        <td width="20%">&nbsp;</td>
                      </tr>
                      <tr>
                      <% String frdt = (mode > 0) ?  ref.getDate("from_date") : ""; %>
                        <td><input type="text" name="from_date" id="from_date" class="style2" style="width:70px; text-align:center" value="<%=frdt%>"></td>
                        <td><a  onclick="popUpCalendar(this,'from_date','dd-mmm-yy');"><IMG width="19" height="19" border="0" src="../shared/images/calendar.gif" title="dd-MMM-yy (example: 01-Jan-04)"></a></td>
                      <% String todt = (mode > 0) ?  ref.getDate("to_date") : ""; %>  
                        <td><input type="text" name="to_date" id="to_date" class="style2" style="width:70px; text-align:center" value="<%=todt%>"></td>
                        <td><a onclick="popUpCalendar(this,'to_date','dd-mmm-yy');"><IMG width="20" height="20" border="0" src="../shared/images/calendar.gif" title="dd-MMM-yy (example: 01-Jan-04)"></a></td>
                      </tr>
                      <tr>
                        <td align="right">Service Contract No &nbsp;</td>
                        <% String svrcntno = (mode > 0) ?  ref.getString("service_contract_no") : ""; %>
                        <td colspan="4"><input type="text" name="service_contract_no" id="service_contract_no" class="style2" style="width:95%;" value="<%=svrcntno%>"></td>
                      </tr>
                    </table></td>
                    <td width="54%"  valign="top"><table width="100%"  border="0" cellpadding="1" cellspacing="1" class="style2">
  <tr>
    <td colspan="2" align="right">Shipper &nbsp;</td>
    <td colspan="5" ><select name="shipper_id" id="shipper_id" class="style2" style="width:100%;" onChange="">
      <option value="0"></option>
      <%task.getResponse().setOption(task.getCompanyList("buyer,seller"));%>
      <% int shipperid = (mode > 0) ?  ref.getIntValue("shipper_id") : 0; %>
      <%task.getResponse().setSelected("shipper_id", ref.getIntValue("shipper_id"));//task.getResponse().setSelected("shipper_id", shipperid);%>
    </select></td>
  </tr>
  <tr>
    <td colspan="2" align="right">Consignee &nbsp;</td>
    <td colspan="5" valign="top"><select name="consignee_id" id="consignee_id" class="style2" style="width:100%;" onChange="">
        <option value=""></option>
        <%task.getResponse().setOption(task.getCompanyList("buyer"));%>
        <% int consigneeid = (mode > 0) ?  ref.getIntValue("consignee_id") : 0; %>
        <%task.getResponse().setSelected("consignee_id",consigneeid);%>
    </select></td>
  </tr>
  <tr>
    <td colspan="2" align="right">Notify Party 1 &nbsp;</td>
    <td colspan="5" valign="top"><select name="notify_party_id1" id="notify_party_id1" class="style2" style="width:100%;" onChange="">
        <option value=""></option>
        <%task.getResponse().setOption(task.getCompanyList("buyer,seller"));%>
        <% int notifyid1 = (mode > 0) ?  ref.getIntValue("notify_party_id1") : 0; %>
        <%task.getResponse().setSelected("notify_party_id1",notifyid1);%>
    </select></td>
  </tr>
  <tr>
    <td colspan="2" align="right">Notify Party 2 &nbsp;</td>
    <td colspan="5" valign="top"><select name="notify_party_id2" id="notify_party_id2" class="style2" style="width:100%;" onChange="">
        <option value=""></option>
        <%task.getResponse().setOption(task.getCompanyList("buyer,seller"));%>
        <% int notifyid2 = (mode > 0) ?  ref.getIntValue("notify_party_id2") : 0; %>
        <%task.getResponse().setSelected("notify_party_id2",notifyid2);%>
    </select></td>
  </tr>
  <tr>
    <td colspan="2" align="right">Shipping Line &nbsp;</td>
    <td colspan="5" valign="top"><select name="shipping_line_id" id="shipping_line_id" class="style2" style="width:100%;" onChange="">
      <option value=""></option>
      <%task.getResponse().setOption("shipping_line_master");%>
      <% int shiplineid = (mode > 0) ?  ref.getIntValue("shipping_line_id") : 0; %>
      <%task.getResponse().setSelected("shipping_line_id",shiplineid);%>
    </select></td>
  </tr>
  <tr>
  	<% String FeederVessel = (mode > 0) ?  ref.getString("feeder_vessel") : ""; %>
    <td colspan="2" align="right">Feeder Vessel &nbsp;</td>
    <td colspan="5" valign="top"><input type="text" name="feeder_vessel" id="feeder_vessel" class="style2" style="width:100%;" value="<%=FeederVessel%>"></td>
  </tr>
  <tr>
    <td colspan="2" align="right">ETS&nbsp;</td>
    <% String fvets = (mode > 0) ?  ref.getDate("feeder_vessel_ets") : ""; %>
    <td width="70"><input type="text" name="feeder_vessel_ets" id="feeder_vessel_ets" class="style2" style="width:70px; text-align:center" value="<%=fvets%>"></td>
    <td width="25"><a onclick="popUpCalendar(this,'feeder_vessel_ets','dd-mmm-yy');"><IMG width="18" height="19" border="0" src="../shared/images/calendar.gif" title="dd-MMM-yy (example: 01-Jan-04)"></a></td>
    <td width="36" align="right">ETA</td>
    <% String fveta = (mode > 0) ?  ref.getDate("feeder_vessel_eta") : ""; %>
    <td width="70"><input type="text" name="feeder_vessel_eta" id="feeder_vessel_eta" class="style2" style="width:70px; text-align:center" value="<%=fveta%>"></td>
    <td width="55"><a onclick="popUpCalendar(this,'feeder_vessel_eta','dd-mmm-yy');"><IMG width="18" height="19" border="0" src="../shared/images/calendar.gif" title="dd-MMM-yy (example: 01-Jan-04)"></a></td>
  </tr>
  <tr>
    <td colspan="2" align="right">Ocean Vessel &nbsp;</td>
    <% String oceanvessel = (mode > 0) ?  ref.getString("ocean_vessel") : ""; %>
    <td colspan="5" valign="top"><input type="text" name="ocean_vessel" id="ocean_vessel" class="style2" style="width:100%;" value="<%=oceanvessel%>"></td>
  </tr>
  <tr>
    <td colspan="2" align="right">ETS&nbsp;</td>
     <% String ets = (mode > 0) ?  ref.getDate("ocean_vessel_ets") : ""; %>
    <td width="70"><input type="text" name="ocean_vessel_ets" id="ocean_vessel_ets" class="style2" style="width:70px; text-align:center" value="<%=ets%>"></td>
    <td width="25"><a onclick="popUpCalendar(this,'ocean_vessel_ets','dd-mmm-yy');"><IMG width="18" height="19" border="0" src="../shared/images/calendar.gif" title="dd-MMM-yy (example: 01-Jan-04)"></a></td>
    <td width="36" align="right">ETA</td>
    <% String eta = (mode > 0) ?  ref.getDate("ocean_vessel_eta") : ""; %>
    <td width="70"><input type="text" name="ocean_vessel_eta" id="ocean_vessel_eta" class="style2" style="width:70px; text-align:center" value="<%=eta%>"></td>
    <td width="55"><a onclick="popUpCalendar(this,'ocean_vessel_eta','dd-mmm-yy');"><IMG width="18" height="19" border="0" src="../shared/images/calendar.gif" title="dd-MMM-yy (example: 01-Jan-04)"></a></td>
  </tr>
  <tr>
    <td colspan="2" align="right">Port of Loading &nbsp;</td>
    <td colspan="5"><select name="port_loading_id" id="port_loading_id" class="style2" style="width:100%;" onChange="">
        <option value="0"></option>
        <%task.getResponse().setOption(task.getPort_List(null));%>
        <% int portload = (mode > 0) ?  ref.getIntValue("port_loading_id") : 0; %>
        <%task.getResponse().setSelected("port_loading_id",portload);%>
    </select></td>
  </tr>
  <tr>
    <td colspan="2" align="right">Place of Delivery &nbsp;</td>
    <td colspan="5"><select name="place_delivery_id" id="place_delivery_id" class="style2" style="width:100%;" onChange="">
        <option value="0"></option>
        <%task.getResponse().setOption("city_master");%>
         <% int placedelvyd = (mode > 0) ?  ref.getIntValue("place_delivery_id") : 0; %>
        <%task.getResponse().setSelected("place_delivery_id",placedelvyd);%>
    </select></td>
  </tr>
  <tr>
    <td colspan="2" align="right">Port of Discharge &nbsp;</td>
    <td colspan="5"><select name="port_discharge_id" id="port_discharge_id" class="style2" style="width:100%;" onChange="">
        <option value="0"></option>
        <%task.getResponse().setOption(task.getPort_List(null));%>
        <% int portdischrg = (mode > 0) ?  ref.getIntValue("port_discharge_id") : 0; %>
        <%task.getResponse().setSelected("port_discharge_id",portdischrg);%>
    </select></td>
  </tr>
  <tr>
    <td colspan="2" align="right">Container Status &nbsp;</td>
    <td colspan="5"><select name="container_status" id="container_status" class="style2" style="width:100%;" onChange="">
        <option value=""></option>
        <option value="FCL/FCL">FCL/FCL</option>
        <option value="LCL/FCL">LCL/FCL</option>
        <% String containerstatus = (mode > 0) ?  ref.getStringValue("container_status") : ""; %>
        <%task.getResponse().setSelected("container_status",containerstatus);%>
    </select></td>
  </tr>
  <tr>
    <td colspan="2" align="right">Weight Cert. By &nbsp;</td>
    <td colspan="5"><select name="weight_controller_id" id="weight_controller_id" class="style2" style="width:100%;" onChange="">
        <option value="0"></option>
        <%task.getResponse().setOption(task.getCompanyList("controller"));%>
        <% int wgtcontrolid = (mode > 0) ?  ref.getIntValue("weight_controller_id") : 0; %>
        <%task.getResponse().setSelected("weight_controller_id", wgtcontrolid);%>
    </select></td>
  </tr>
  <tr>
    <td colspan="2" align="right">Quality Cert. By &nbsp;</td>
    <td colspan="5"><select name="quality_controller_id" id="quality_controller_id" class="style2" style="width:100%;" onChange="">
      <option value="0"></option>
      <%task.getResponse().setOption(task.getCompanyList("controller"));%>
      <% int qtycert = (mode > 0) ?  ref.getIntValue("quality_controller_id") : 0; %>
      <%task.getResponse().setSelected("quality_controller_id", qtycert);%>
    </select></td>
  </tr>
</table></td>
                  </tr>
                </table></td>
                </tr>
              <tr>
                <td width="177" align="right">Marking On Bags  &nbsp;<br>
                  <a href="javascript:markingOnBags();" style="color:#0000FF"><em>(Click here for default value)</em></a> &nbsp;</td>
                  <% String marking = (mode > 0) ?  ref.getString("marking_on_bags") : ""; %>
                <td colspan="4"><textarea name="marking_on_bags" id="marking_on_bags" rows="4" class="style2" style="width:100%"><%=marking%></textarea></td>
                </tr>
              <tr>
                <td align="right">Freight &nbsp;</td>
                <% String freight = (mode > 0) ?  ref.getString("freight") : ""; %>
                <td colspan="4"><input type="text" name="freight" id="freight" class="style2" style="width:100%;" value="<%=freight%>"></td>
                </tr>
              <tr>
                <td align="right">Accessories&nbsp;</td>
                <td colspan="4"><table width="100%"  border="1" cellspacing="0" cellpadding="0">
                  <tr>
                    <td><table width="100%"  border="0" cellpadding="0" cellspacing="1" class="style2">
                        <tr align="center" bgcolor="EEEEEE" style="font-weight:bold">
                          <td>Items</td>
                          <td>Unit</td>
                          <td>Quantity</td>
                          <td>Supplier</td>
                        </tr>
<%

	ResultSet ra = task.get_Accessory_Detail();
	int rows=0;
	while (ra.next()) {
		int i = ra.getRow();

		//System.out.println("Count----------------------"+i);
%>						
						<input type="hidden" name="ac_id_<%=i%>"         id="ac_id_<%=i%>"         value="<%=ra.getInt("id")%>">
						<input type="hidden" name="accessory_id_<%=i%>"  id="accessory_id_<%=i%>"  value="<%=ra.getInt("accessory_id")%>">
                        <tr>
                        <% String name = (mode > 0) ?  ra.getString("name") : ""; %>
                          <td width="24%" align="right"><%=name%> &nbsp;</td>
                          <% String unit = (mode > 0) ?  ra.getString("unit") : ""; %>
                          <td width="24%" align="center"><%=unit%></td>
                          <% float qty = (mode > 0) ?  ra.getFloat("quantity") : 0; %>
                          <td width="15%" align="center"><input type="text" name="quantity_<%=i%>" id="quantity_<%=i%>" class="style2" style="width:60px; text-align:right" value="<%=Utils.numberToStr(qty,1)%>"></td>
                          <td width="37%"><select name="supplier_id_<%=i%>" id="supplier_id_<%=i%>" class="style2" style="width:100%;" onChange="">
                              <option value="0"></option>
                              <%task.getResponse().setOption(task.getCompanyList("service"));%>
                              <% int sid = (mode > 0) ?  ra.getInt("supplier_id") : 0; %>
                              <%task.getResponse().setSelected("supplier_id_" + i, sid);%>
                          </select></td>
                        </tr>
<%

		rows=rows+1;
		//System.out.println("Rows------------------------"+rows);
	}
%>						
                    </table>
                        <strong>
                      <input name="acc_rows" type="hidden" id="acc_rows" value="<%=rows%>" />
                      </strong></td>                      
                  </tr>
                </table></td>
                </tr>
              <tr>
                <td align="right">LC No &nbsp;</td>
                <% String lcno = (mode > 0) ?  ref.getString("lc_no") : ""; %>
                <td width="150"><input type="text" name="lc_no" id="lc_no" class="style2" style="width:150px;" value="<%=lcno%>"></td>
                <td width="125" align="right">LC Date &nbsp;</td>
                <% String lcdt = (mode > 0) ?  ref.getDate("lc_date") : ""; %>
                <td width="70"><input type="text" name="lc_date" id="lc_date" class="style2" style="width:70px; text-align:center" value="<%=lcdt%>"></td>
                <td width="320"><a onclick="popUpCalendar(this,'lc_date','dd-mmm-yy');"><IMG width="20" height="20" border="0" src="../shared/images/calendar.gif" title="dd-MMM-yy (example: 01-Jan-04)"></a></td>
              </tr>
              <tr>
                <td align="right">Invoice No &nbsp;</td>
                <td width="150"><input type="text" name="invoice_no" id="invoice_no" class="style2" style="width:150px;" value="<%=ref.getString("invoice_no")%>"></td>
                <td width="125" align="right">Invoice Date &nbsp;</td>
                <td width="70"><input type="text" name="invoice_date" id="invoice_date" class="style2" style="width:70px; text-align:center" value="<%=ref.getDate("invoice_date")%>"></td>
                <td width="320"><a onclick="popUpCalendar(this,'invoice_date','dd-mmm-yy');"><IMG width="20" height="20" border="0" src="../shared/images/calendar.gif" title="dd-MMM-yy (example: 01-Jan-04)"></a></td>
              </tr>
              <tr>
                <td align="right">B/L Number &nbsp;</td>
                <% String blno = (mode > 0) ? ref.getString("bill_of_lading_no") : ""; %>
                <td><input type="text" name="bill_of_lading_no" id="bill_of_lading_no" class="style2" style="width:150px;" value="<%=blno%>"></td>
                <td align="right">B/L Date &nbsp;</td>
                <% String bldt = (mode > 0) ? ref.getDate("bill_of_lading_date") : ""; %>
                <td><input type="text" name="bill_of_lading_date" id="bill_of_lading_date" class="style2" style="width:70px; text-align:center" value="<%=bldt%>"></td>
                <td><a onclick="popUpCalendar(this,'bill_of_lading_date','dd-mmm-yy');"><IMG width="20" height="20" border="0" src="../shared/images/calendar.gif" title="dd-MMM-yy (example: 01-Jan-04)"></a></td>
              </tr>
              <tr>
                <td align="right">Required Documents &nbsp;</td>
                <td colspan="4"><table width="100%"  border="1" cellspacing="0" cellpadding="0">
                  <tr>
                    <td><table width="100%"  border="0" cellspacing="1" cellpadding="1" class="style2">
                        <%
						if (mode > 0)
						{
	ResultSet dl = task.getDocument_List();
	while (dl.next()) {
		int i  = dl.getRow();
		id = dl.getInt("id");
%>
                        <tr>
                          <td width="5%" align="right"><input type="checkbox" name="selected_<%=i%>_" id="selected_<%=i%>_" value="1" onClick="cbxClick(this)" <%=dl.getInt("selected")==1?"checked":""%>></td>
                          <td width="77%"><%=dl.getString("name")%></td>
                          </tr>
                        <input type="hidden" name="selected_<%=i%>" id="selected_<%=i%>" value="<%=dl.getInt("selected")%>">
                        <input type="hidden" name="id_<%=i%>" id="id_<%=i%>" value="<%=dl.getInt("id")%>">
                        <input type="hidden" name="document_id_<%=i%>" id="document_id_<%=i%>" value="<%=dl.getInt("document_id")%>">
                        <%
	}
	}
%>
                    </table></td>
                  </tr>
                </table></td>
              </tr>
              <tr>
                <td align="right"><label id="e316">Remark &nbsp;</label></td>
                <% String remarks = (mode > 0) ?  ref.getString("remark") : ""; %>
                <td colspan="4"><textarea name="remark" id="remark" rows="3" class="style2" style="width:100%"><%=remarks%></textarea></td>
              </tr>
              <tr>
                <td align="right"><label id="e317">Completed &nbsp;</label></td>
                <% int comp = (mode > 0) ?  ref.getIntValue("status") : 0; %>
                <td colspan="4"><input type="checkbox" name="completed_" id="completed_" value="checkbox" onClick="cbxClick(this,2)" <%=comp==2?"checked":""%>></td>
					 <input type="hidden" name="completed"  id="completed"  value="<%=comp%>">
                </tr>
              <tr>
                <td align="right">By Order Of &nbsp;</td>
                <td colspan="4"><%//=ref.getString("user_name")%></td>
              </tr>
            </table></td>
  		</tr>
	</table></td>
  </tr>
	<tr>
	  <td>&nbsp;</td>
		<td><table width="100%"  border="0">
          <tr>
            <td width="4%"><img src="images/update.gif" width="15" height="15" border="0" onClick="doUpdate()"></td>
            <td align="right"><img src="images/invoice.jpg" width="55" height="18" onClick="">
			<img src="images/packing-list.jpg" width="55" height="18" onClick="">
			<img src="images/report.jpg" width="55" height="18" border="0" onClick="">
<!---			<img style="dis " src="images/allocation.jpg" width="55" height="18" border="0" onClick=""> --->
			<img src="images/listview.jpg" width="55" height="18" border="0" onClick="listView();"></td>
          </tr>
        </table></td>
	</tr>
	
	<tr>

	  <td>&nbsp;</td>
	  <td><input type="button" name="cmdAlc" id="cmdAlc" value="Allocate" onclick="ajaxTable('traffic.si.alctable.jsp')";>
      </td>
    </tr>
	<tr>
	  <td>&nbsp;</td>
      
      
	  <td><table width="100%"><tr><td >

	  </td></tr>
	<tr>
		<td class="style3">
        <table width="99%"  border="1" cellpadding="1" cellspacing="1" class="style2" bordercolor="#EEEEEE">
                <tr align="center" bgcolor="#EEEEEE" class="style3">
                    <td width="10%" class="style2">Id</td>
                    <td width="18%" class="style2">Ref.No</td>
                    <td width="18%" class="style2">Tons</td>
                    <td width="21%" class="style2">Grade</td>
                    <td width="18%" class="style2">Available.Qty</td>
                    <td width="15%" class="style2">Qty To Alc</td>
                </tr>
                <tr align="center" class="style3">
                  <td colspan="6" class="style2" id="AjTbl">&nbsp;</td>
                </tr>
         </table>
         </td>
	</tr>
	<tr>
		<td align="left"><img src="images/update.gif" width="15" height="15" onClick="doUpdAllocation()"/></td>
	</tr>
		</table>
	</td>


    </tr>
	<tr>
	  <td>&nbsp;</td>
	  <td><label id="wn_plus_" style="font-weight:bold; color:#0099CC">+</label><a href="javascript:showClicked();" style="color:#0099CC"><strong>Containers</strong></a></td>
    </tr>
	<tr id="wn_show_" style="display:none">
	  <td>&nbsp;</td>
	  <td><table width="100%"  border="1" cellspacing="0" cellpadding="0">
        <tr>
          <td><table width="100%"  border="0" cellpadding="1" cellspacing="1" class="style2">
              <tr bgcolor="#EEEEEE" style="font-weight:bold" align="center">
                <td width="4%">No</td>
                <td width="21%">WN Ref </td>
                <td width="21%">Container No </td>
                <td width="14%">Seal No </td>
                <td width="8%">Net<br>(Mts)</td>
                <td width="7%">Bags</td>
                <td width="8%">Tare<br>(Mts)</td>
                <td width="9%">Gross<br>(Mts)</td>
                <td width="2%">Del</td>
                <td width="3%">Sav</td>
              </tr>
<%
	rc = new Record(task.getContainer_Detail());
	rc.beforeFirst();
	int no = 1;
	float total_gross_weight = 0;
	float total_tare_weight  = 0;
	float total_net_weight   = 0;
	int total_no_of_bags = 0;
	while (rc.next()) 
	{
		System.out.println("Container Loop");
		total_gross_weight += rc.getFloatValue("gross_weight");
		total_tare_weight  += rc.getFloatValue("tare_weight");
		total_net_weight   += rc.getFloatValue("net_weight");
		total_no_of_bags   += rc.getIntValue("no_of_bags");
%>
              <input type="hidden" name="wn_id_<%=no%>"  id="wn_id_<%=no%>"  value="<%=rc.getInt("id")%>">
              <tr id="wn_<%=no%>" onClick="highlightOn(this,2);">
                <td bgcolor="#EEEEEE" align="center"><%=rc.getRow()%></td>
                <td align="center"><input type="text" name="ref_number_<%=no%>"      id="ref_number_<%=no%>" class="style2" style="width:100%;" value="<%=rc.getString("ref_number")%>" readonly=""></td>
                <td align="center"><input type="text" name="container_no_<%=no%>"    id="container_no_<%=no%>" class="style2" style="width:100%;" value="<%=rc.getString("container_no")%>"></td>
                <td align="center"><input type="text" name="seal_no_<%=no%>"         id="seal_no_<%=no%>" class="style2" style="width:100%;" value="<%=rc.getString("seal_no")%>"></td>
                <td align="center"><input type="text" name="wn_net_weight_<%=no%>"   id="wn_net_weight_<%=no%>"   class="style2" style="width:100%; text-align:right" value="<%=rc.getFloat("net_weight",1)%>"   onChange=""></td>
                <td align="center"><input type="text" name="wn_no_of_bags_<%=no%>"   id="wn_no_of_bags_<%=no%>"   class="style2" style="width:100%; text-align:right" value="<%=rc.getInt("no_of_bags")%>"       onChange=""></td>
                <td align="center"><input type="text" name="wn_tare_weight_<%=no%>"  id="wn_tare_weight_<%=no%>"  class="style2" style="width:100%; text-align:right" value="<%=rc.getFloat("tare_weight",1)%>"  onChange=""></td>
                <td align="center"><input type="text" name="wn_gross_weight_<%=no%>" id="wn_gross_weight_<%=no%>" class="style2" style="width:100%; text-align:right" value="<%=rc.getFloat("gross_weight",1)%>" onChange=""></td>
                <td align="center"><img src="../shared/images/delete.gif" width="15" height="15" onClick=""></td>
                <td align="center"><img src="../shared/images/update.jpg" width="15" height="15" onClick=""></td>
              </tr>
<%
		no++;
	}
	no=0;
%>
              <input type="hidden" name="wn_id_<%=no%>"  id="wn_id_<%=no%>"  value="-1">
              <tr id="wn_<%=no%>" onClick="highlightOn(this,1);" style="display:none">
                <td bgcolor="#EEEEEE" align="center"><strong><%=no%></strong></td>
                <td align="center"><input type="text" name="ref_number_<%=no%>"      id="ref_number_<%=no%>" class="style2" style="width:100%;" value="<%//=task.getNew_Container()%>"></td>
                <td align="center"><input type="text" name="container_no_<%=no%>" id="container_no_<%=no%>" class="style2" style="width:100%;" value=""></td>
                <td align="center"><input type="text" name="seal_no_<%=no%>" id="seal_no_<%=no%>" class="style2" style="width:100%;" value=""></td>
                <td align="center"><input type="text" name="wn_net_weight_<%=no%>"   id="wn_net_weight_<%=no%>"   class="style2" style="width:100%; text-align:right" value=""  onChange=""></td>
                <td align="center"><input type="text" name="wn_no_of_bags_<%=no%>"   id="wn_no_of_bags_<%=no%>"   class="style2"  style="width:100%; text-align:right" value="" onChange=""></td>
                <td align="center"><input type="text" name="wn_tare_weight_<%=no%>"  id="wn_tare_weight_<%=no%>"  class="style2" style="width:100%; text-align:right" value=""  onChange=""></td>
                <td align="center"><input type="text" name="wn_gross_weight_<%=no%>" id="wn_gross_weight_<%=no%>" class="style2" style="width:100%; text-align:right" value=""  onChange=""></td>
                <td align="center"><img src="../shared/images/delete.gif" width="15" height="15" onClick=""></td>
                <td align="center"><img src="../shared/images/update.jpg" width="15" height="15" onClick="doUpdateWNI()"></td>
              </tr>
              <tr>
                <td><img src="../shared/images/new.gif" width="15" height="15" title="Input New Weight Certificate" onClick="new_Container(<%=no%>)"></td>
                <td>&nbsp;</td>
                <td>&nbsp;</td>
                <td align="right"><strong>Total</strong></td>
                <td align="right"><strong><label id="wn_net_weight_"><%=Utils.numberToStr(total_net_weight,1)%></label></strong></td>
                <td align="right"><strong><label id="wn_no_of_bags_"><%=total_no_of_bags%></label></strong></td>
                <td align="right"><strong><label id="wn_tare_weight_"><%=Utils.numberToStr(total_tare_weight,1)%></label></strong></td>
                <td align="right"><strong><label id="wn_gross_weight_"><%=Utils.numberToStr(total_gross_weight,1)%></label></strong></td>
                <td>&nbsp;</td>
                <td>&nbsp;</td>
              </tr>
          </table></td>
        </tr>
      </table></td>
    </tr>
<%
	String NewRec = request.getParameter("new_rec");
	if (NewRec.compareTo("1")==0)
	{
%>
	<script>
		doAddNewSi();
	</script>
<%	
	}
%>	
	<%		System.out.println("Hello");%>
	<input type="hidden" name="uid"  id="uid"  value="<%=user.getuid()%>">
	<input type="hidden" name="task_id"  id="task_id"  value="0">
	<input type="hidden" name="view" id="view" value="<%//=task.getRequest().getIntValue("view")%>">
    <input type="hidden" name="contract_id"  id="contract_id"  value="<%=ref.getInt("contract_id")%>">
	<input type="hidden" name="no" id="no" value="0">	
	<input type="hidden" name="wn_show" id="wn_show" value="<%//=task.getRequest().getIntValue("wn_show")%>">	
</table>

</form>


<%@include file="../footer.jsp"%>
